package buildcode;

import java.util.HashMap;
import java.util.Map;

public class Context {
    private static final String SERVLET_CONTEXT_PATH_KEY = "SERVLET_CONTEXT_PATH_KEY";
    private static final String APPLICATION_NAME_KEY = "APPLICATION_NAME_KEY";
    private static final String TABLE_PRFIX_KEY = "TABLE_PRFIX_KEY";
    private static final String AUTHOR_KEY = "AUTHOR_KEY";
    private static final String DELFLAG_KEY = "DELFLAG_KEY";
    private static final String VELOCITY_TOOL_KEY = "VELOCITY_TOOL_KEY";

    private static final ThreadLocal<Map<String, Object>> map = ThreadLocal.withInitial(HashMap::new);

    static {
        put(VELOCITY_TOOL_KEY, new HashMap<String, Object>());
    }

    public static void put(String key, Object val) {
        map.get().put(key, val);
    }

    @SuppressWarnings("unchecked")
    public static <T> T get(String key) {
        return (T) map.get().get(key);
    }

    public static String getServletContextPath() {
        return get(SERVLET_CONTEXT_PATH_KEY);
    }

    public static void setServletContextPath(String servletContextPath) {
        put(SERVLET_CONTEXT_PATH_KEY, servletContextPath);
    }

    public static String getApplicationName() {
        return get(APPLICATION_NAME_KEY);
    }

    public static void setApplicationName(String applicationName) {
        put(APPLICATION_NAME_KEY, applicationName);
    }

    public static String getTablePrfix() {
        return get(TABLE_PRFIX_KEY);
    }

    public static void setTablePrfix(String tablePrfix) {
        put(TABLE_PRFIX_KEY, tablePrfix);
    }

    public static String getAuthor() {
        return get(AUTHOR_KEY);
    }

    public static void setAuthor(String author) {
        put(AUTHOR_KEY, author);
    }

    public static String getDelFlag() {
        return get(DELFLAG_KEY);
    }

    public static void setDelFlag(String author) {
        put(DELFLAG_KEY, author);
    }

    public static void addVelocityTool(String key, Object tool) {
        Map<String, Object> map = get(VELOCITY_TOOL_KEY);
        map.put(key, tool);
    }

    public static Map<String, Object> getVelocityTools() {
        return get(VELOCITY_TOOL_KEY);
    }

}
